/*AyflEomXWyqCHfdTxzWda+ZiNDhxOZJeZF/oshAh0uo=*/
/*
 * @Author: xiahui 
 * @PageInfo: 采购合同维护列表态
 * @Date: 2019-01-10 16:48:57 
 * @Last Modified by: zhangmi
 * @Last Modified time: 2021-09-10 12:09:57
 */
import React, { Component } from 'react';
import { createPage, createPageIcon, high, base } from 'nc-lightapp-front';
import { initTemplate } from './init';
import { AREA, URL, PAGECODE, DATASOURCECACHE, UISTATUS, FIELDS } from '../constance';
import { buttonClick, searchBtnClick, pageInfoClick } from './btnClicks';
import { buttonControl } from './viewControl/buttonControl';
import { searchAfterEvent } from './afterEvents';
import ApprovalTrans from 'uap/common/components/approvalTrans';
import transtypeUtils from '../../../../scmpub/scmpub/pub/tool/transtypeUtils';
import DocManagement from '../../pub/components/DocManagement';
import ControlScopeDlg from '../../pub/components/ControlScopeDlg';
import commitBtnClick from './btnClicks/commitBtnClick';
import MulTabPane from 'scmpub/scmpub/components/MulTabPane';
import { initLang, getLangByResId } from '../../../../scmpub/scmpub/pub/tool/multiLangUtil';
import { createListTitle } from '../../../../scmpub/scmpub/pub/tool/titleUtil';
import ApproveDetail from 'uap/common/components/ApproveDetail';
import NCUploader from 'uap/common/components/NCUploader';
const { BillTrack } = high;
const { NCAffix, NCDiv } = base;
const { setQueryDefaultValue } = transtypeUtils;

class PurdailyList extends Component {
	constructor(props) {
		super(props);

		props.use.table(AREA.listTableId);
		props.use.search(AREA.searchId);

		this.state = {
			pk: '',
			billtype: '',
			showTrack: false,
			showApproveInfo: false,
			showUploader: false,
			showPane: false, // 变更历史
			target: null,
			vbillcode: null,
			showControl: false, // 合同范围控制
			isBatchControl: false, // 是否批量控制
			compositedisplay: false, // 提交指派组件显示隐藏
			compositedata: null, // 提交指派组件数据
			showDoc: false //半结构化文档管理弹窗
		};
		// 当前执行提交的数据（为提交指派提供）
		this.commitInfo = {
			isBatch: false,
			record: null,
			index: null
		};
		this.paneData; // 变更历史
		this.reason = null; // 操作原因
		initLang(this, [ '4004purdaily' ], 'ct', initTemplate.bind(this, this.props));
	}

	toggleDocShow = () => {
		this.setState({
			showDoc: !this.state.showDoc
		});
	};

	// 提交指派获取结果后重新进行提交
	getResult = (value) => {
		//重新执行提交操作重新执行提交操作
		let { record, index } = this.commitInfo;
		// if (this.commitInfo.isBatch) {
		// 	commitBtnClick.call(this, this.props, record, index, value);
		// }
		commitBtnClick.call(this, this.props, record, index, value);
		this.setState({ compositedisplay: false });
	};

	// 脚本操作对话框回调
	changeReason = (reason) => {
		this.reason = reason;
	};

	render() {
		const { button, search, table, modal, BillHeadInfo, socket } = this.props;
		const { createButtonApp } = button;
		const { NCCreateSearch } = search;
		const { createSimpleTable } = table;
		const { createModal } = modal;
		let rows = this.props.table.getCheckedRows(AREA.listTableId);
		let newpk = '';
		if (rows && rows[0] && rows[0].data) {
			newpk = rows[0].data.values.pk_ct_pu.value; // 主键
		}

		return (
			<div className="nc-bill-list">
				{socket.connectMesg({
					tableAreaCode: AREA.list_head,
					billpkname: FIELDS.pk_ct_pu,
					billtype: 'Z2'
				})}
				<NCAffix>
					<NCDiv areaCode={NCDiv.config.HEADER} className="nc-bill-header-area">
						<div className="header-title-search-area">
							{/* 国际化处理：采购合同维护*/}
							{createListTitle(this)}
						</div>
						<div className="header-button-area">
							{createButtonApp({
								area: AREA.list_head,
								onButtonClick: buttonClick.bind(this)
							})}
						</div>
					</NCDiv>
				</NCAffix>
				<div className="nc-bill-search-area">
					{NCCreateSearch(AREA.searchId, {
						dataSource: DATASOURCECACHE.dataSourceListCacheKey,
						clickSearchBtn: searchBtnClick.bind(this),
						onAfterEvent: searchAfterEvent.bind(this),
						renderCompleteEvent: this.querySchemeAfterEvent,
						statusChangeEvent: this.querySchemeAfterEvent
					})}
				</div>
				<div className="nc-bill-table-area">
					{createSimpleTable(AREA.listTableId, {
						dataSource: DATASOURCECACHE.dataSourceListCacheKey,
						pkname: FIELDS.pk_ct_pu,
						showIndex: true, //显示序号
						showCheck: true,
						handlePageInfoChange: pageInfoClick.bind(this),
						onSelected: onSelect.bind(this),
						onSelectedAll: onSelect.bind(this),
						onRowDoubleClick: (record, index, e) => {
							this.props.pushTo(URL.card, {
								status: UISTATUS.browse,
								id: record[FIELDS.pk_ct_pu].value,
								pagecode: PAGECODE.cardPagecode
							});
						}
						// componentInitFinished: () => {
						// 	setTimeout(() => {
						// 		let checkArr = this.props.table.getCheckedRows(AREA.listTableId);
						// 		buttonControl(this.props, checkArr);
						// 	}, 1);
						// }
					})}
				</div>
				{this.state.compositedisplay && (
					<ApprovalTrans
						title={getLangByResId(this, '4004PURDAILY-000049')} /* 国际化处理： 指派*/
						data={this.state.compositedata}
						display={this.state.compositedisplay}
						getResult={this.getResult.bind(this)}
						cancel={() => {
							this.setState({ compositedisplay: false });
						}}
					/>
				)}
				<BillTrack
					show={this.state.showTrack}
					close={() => {
						this.setState({ showTrack: false });
					}}
					pk={this.state.pk}
					type="Z2"
				/>
				<ApproveDetail
					show={this.state.showApproveInfo}
					close={() => {
						this.setState({
							showApproveInfo: false
						});
					}}
					billtype={this.state.billtype}
					billid={this.state.pk}
				/>
				{this.state.showUploader && (
					<NCUploader
						billId={this.state.pk}
						target={this.state.target}
						onHide={() => {
							this.setState({
								showUploader: false
							});
						}}
						// placement={'bottom_right'}
						billNo={this.state.vbillcode}
						billcode={newpk}
						pk_billtypecode={'Z2'}
					/>
				)}
				<ControlScopeDlg
					show={this.state.showControl}
					isBatch={this.state.isBatchControl}
					pk={this.state.pk}
					close={() => {
						this.setState({
							showControl: false
						});
					}}
				/>
				<DocManagement
					show={this.state.showDoc}
					billId={this.state.pk}
					billType="Z2"
					toggleShow={this.toggleDocShow}
					asyncTree={this.props.asyncTree}
				/>
				{this.state.showPane && (
					<MulTabPane
						show={this.state.showPane}
						pagecode={PAGECODE.histPagecode}
						title={getLangByResId(this, '4004PURDAILY-000066')} /* 国际化处理： 采购合同变更历史*/
						headcode={AREA.cardFormId}
						bodycode={[
							AREA.cardTableId,
							AREA.cardTermId,
							AREA.cardFeeId,
							AREA.cardMemoraId,
							AREA.cardChangeId,
							AREA.cardExecutId
						]}
						data={this.paneData}
						close={() => {
							this.setState({ showPane: false });
						}}
						showBodyData={true}
					/>
				)}
				{createModal('code-config')}
				{createModal('ScriptActionDlg')}
				{createModal('printService', {
					className: 'print-service'
				})}
				<iframe id="printServiceframe" name="printServiceframe" style={{ display: 'none' }} />
			</div>
		);
	}

	querySchemeAfterEvent = () => {
		// 交易类型发布的节点需要设置交易类型默认值
		setQueryDefaultValue.call(this, this.props, AREA.searchId, FIELDS.ctrantypeid);
		searchAfterEvent.call(this, FIELDS.pk_org);
	};
}

/**
 * SimpleTable 选中行触发事件
 * @param {*} props 
 * @param {*} moduleId 
 * @param {*} record 
 * @param {*} index 
 * @param {*} status 
 */
function onSelect(props, moduleId, record, index, status) {
	buttonControl.call(this, props, props.table.getCheckedRows(moduleId));
}

PurdailyList = createPage({
	billinfo: {
		billtype: 'grid',
		pagecode: PAGECODE.listPagecode,
		bodycode: {
			[AREA.listTableId]: 'table'
		}
	}
})(PurdailyList);

export default PurdailyList;

/*AyflEomXWyqCHfdTxzWda+ZiNDhxOZJeZF/oshAh0uo=*/